#!/usr/bin/env node

const http = require('http');

http.createServer((req,res)=>{
  if(req.url !== '/'){
    err(req,res);
    return;
  }

  console.log(`${req.method} ${req.url} HTTP/${req.httpVersion}`);
  console.log(req.headers);
  console.log('');

  if(req.method === 'POST'){
    req.pipe(process.stdout);
    res.end('ok');
  }
  else{ 
    err(req,res);
  }
}).listen(8080);

function err(req,res){
  res.statusCode = 404;
  res.end(`${req.url} NOT FOUND`);
  //console.log('404 not found');
}



